package com.cip.admin.action;

import java.util.List;
import java.util.Locale;

import com.cip.admin.model.Staff;
import com.cip.admin.model.User;
import com.cip.admin.service.StaffService;
import com.cip.common.util.SecurityUtil;
import com.cip.webapp.action.BaseAction;

public class StaffAction extends BaseAction {

	private static final long serialVersionUID = 1L;

	private StaffService staffService;

	private Staff staff;
	
	private List<Staff> staffList;

	public void setStaffService(StaffService staffService) {
		this.staffService = staffService;
	}

	public StaffService getStaffService() {
		return staffService;
	}

	public String showCreateStaff() throws Exception {
		setStaff(new Staff());
		return SUCCESS;
	}

	public String saveOrUpdateStaff() {
		try {
			User user = SecurityUtil.getLoggedInUser();
			staff.setTenantId(user.getTenantId());
			staffService.saveOrUpdateStaff(staff);
		} catch (Exception e) {
			addActionError("Error while adding staff: "+e.getMessage());
			e.printStackTrace();
		} finally {
			saveMessage(getText("staff.added"));
		}
		return SUCCESS;
	}
	
	public String showStaffList() throws Exception {
		
		Locale locale = getRequest().getLocale();
		System.out.println("local===================="+locale);
		String staffString = staffService.getStaffGridList(locale);
		System.out.println("emailConfigString================"+staffString);
				
		getRequest().setAttribute("staffGridString", staffString);
		
		//setStaffList(staffService.getAllStaff());	
		
		return SUCCESS;
	}

	public String showEditStaff() {
		try {
			setStaff(staffService.getStaffById(staff.getId()));
		} catch (Exception e) {
			e.printStackTrace();
		}
		return SUCCESS;
	}

	public void setStaff(Staff staff) {
		this.staff = staff;
	}

	public Staff getStaff() {
		return staff;
	}

	public List<Staff> getStaffList() {
		return staffList;
	}

	public void setStaffList(List<Staff> staffList) {
		this.staffList = staffList;
	}

}
